package com.shopcentre15.shopcentre.FormalShopExplot.Service.Impl.Goods;

import com.github.pagehelper.PageHelper;
import com.shopcentre15.shopcentre.FormalShopExplot.Dao.Goods.GoodsDao;
import com.shopcentre15.shopcentre.FormalShopExplot.Entity.ShopGoods;
import com.shopcentre15.shopcentre.FormalShopExplot.Service.Goods.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import java.security.Key;
import java.util.List;
import java.util.Map;

@Service
public class GoodsImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Override
    public Integer addProduct(Map<String, Object> params) {

        Integer goods = goodsDao.addProduct(params);
        if(goods > 0 ){
            return goods;
        }
        return 0;
    }

    @Override
    public List<ShopGoods> getGoodsList(){

        return goodsDao.getGoodsList();
    }

    @Override
    public List<ShopGoods> getGoodsListByPage(Map<String, Object> params) {
        if(params.get("mid") == null){
            return null;
        }
        List<ShopGoods> goodsListByPage = goodsDao.getGoodsListByPage(params);
        return goodsListByPage;
    }

    @Override
    public Integer getTotalGoodsCount(int mid) {
        if(mid == 0){
            return 0;
        }
        return goodsDao.getTotalGoodsCount(mid);
    }

    @Override
    public List<ShopGoods> getGoodsListByPageHelper(int mid) {
        if(mid == 0){
            return null;
        }
        return goodsDao.getGoodsListByPageHelper(mid);
    }

    @Override
    public Integer UpdateProduct(int id,int state) {
        if(id == 0){
            return 0;
        }
        ShopGoods shopGoods = goodInfo(id);
        Integer state1 = shopGoods.getState();
        if (state1 == 0){
            state1 = 1;
            return goodsDao.UpdateProduct(id,state1);
        }
        return null;
    }

    @Override
    public ShopGoods goodInfo(int id) {
        if(id == 0){
            return null;
        }
        return goodsDao.goodInfo(id);
    }

    @Override
    public Integer updateGoodInfo(Map<String, Object> params) {
        return goodsDao.updateGoodInfo(params);
    }

    @Override
    public List<ShopGoods> getGoodsByTitle(String Keyword, int mid) {
        if (Keyword == null || mid == 0){
            return null;
        }
        return goodsDao.getGoodsByTitle(Keyword,mid);
    }

    @Override
    public Integer UpdateGoodsStateBatch(List<Integer> mids) {
        if(mids == null){
            return 0;
        }
        return goodsDao.UpdateGoodsStateBatch(mids);
    }


}
